<?php
function remove_dashboard_widgets() {
	global $wp_meta_boxes;

	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);

}

add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );

function wpmods_dashboard_widget(){
	global $wp_registered_sidebars;

	$num_posts = wp_count_posts( 'library' );
	$num_pages = wp_count_posts( 'page' );

	$num_authors  = wp_count_terms('authors');

	$num_classcat = wp_count_terms('classcat');
	
	$num_publishers = wp_count_terms('publishers');

	$num_comm = wp_count_comments( );

	echo "\n\t".'<div class="table table_content">';
	echo "\n\t".'<p class="sub">' . __('Summary') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';

	// Posts
	$num = number_format_i18n( $num_posts->publish );
	$text = _n( 'Book', 'Books', intval($num_posts->publish) );
	if ( current_user_can( 'edit_posts' ) ) {
		$num = "<a href='edit.php'>$num</a>";
		$text = "<a href='edit.php'>$text</a>";
	}
	echo '<td class="first b b-posts">' . $num . '</td>';
	echo '<td class="t posts">' . $text . '</td>';

	echo '</tr><tr>';
	/* TODO: Show status breakdown on hover
	if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds.  Don't show if !current_user_can
		$post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
	}
	if ( $can_edit_posts && !empty($num_posts->draft) ) {
		$post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( _n( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
	}
	if ( $can_edit_posts && !empty($num_posts->future) ) {
		$post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( _n( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
	}
	if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
		$pending_text = sprintf( _n( 'There is <a href="%1$s">%2$s post</a> pending your review.', 'There are <a href="%1$s">%2$s posts</a> pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
	} else {
		$pending_text = '';
	}
	*/

	// Library Members
	$result = count_users();

	foreach($result['avail_roles'] as $role => $count)
	if ($role == 'Librarian'){
	echo '<td class="first b b_pages"><a href="users.php">' . $count . '</a></td><td class="t pages"><a href="users.php">' . $role . '</a></td>';}
	echo '</tr><tr>';
	if ($role == 'library-member'){
	echo '<td class="first b b_pages"><a href="users.php">' . $count . __('</a></td><td class="t pages"><a href="users.php">Library Members</a></td>');}



	echo "</tr>";
	do_action('right_now_content_table_end');
	echo "\n\t</table>\n\t</div>";


	echo "\n\t".'<div class="table table_discussion">';
	echo "\n\t".'<p class="sub">' . __('Details') . '</p>'."\n\t".'<table>';
	echo "\n\t".'<tr class="first">';

	// Total Comments
	$num = number_format_i18n( $num_publishers );
	$text = _n( 'Publisher', 'Publishers', $num_publishers );
	if ( current_user_can( 'manage_categories' ) ) {
		$num = "<a href='edit-tags.php?taxonomy=publishers'>$num</a>";
		$text = "<a href='edit-tags.php?taxonomy=publishers'>$text</a>";
	}
	echo '<td class="b b-comments">' . $num . '</td>';
	echo '<td class="last t comments">' . $text . '</td>';

		echo '</tr><tr>';

	// Categories
	$num = number_format_i18n( $num_authors );
	$text = _n( 'Author', 'Authors', $num_authors );
	if ( current_user_can( 'manage_categories' ) ) {
		$num = "<a href='edit-tags.php?taxonomy=authors'>$num</a>";
		$text = "<a href='edit-tags.php?taxonomy=authors'>$text</a>";
	}
	echo '<td class="first b b-cats">' . $num . '</td>';
	echo '<td class="t cats">' . $text . '</td>';

	echo '</tr><tr>';

	// Tags
	$num = number_format_i18n( $num_classcat );
	$text = _n( 'Class/Category', 'Classes/Categories', $num_classcat );
	if ( current_user_can( 'manage_categories' ) ) {
		$num = "<a href='edit-tags.php?taxonomy=classcat'>$num</a>";
		$text = "<a href='edit-tags.php?taxonomy=classcat'>$text</a>";
	}
	echo '<td class="first b b-tags">' . $num . '</td>';
	echo '<td class="t tags">' . $text . '</td>';
	echo "</tr>";
	do_action('right_now_table_end');
	do_action('right_now_discussion_table_end');
	echo "\n\t</table>\n\t</div>";

	echo "\n\t".'<div class="versions">';
	$ct = current_theme_info();

	echo "\n\t<p>";
	if ( !empty($wp_registered_sidebars) ) {
		$sidebars_widgets = wp_get_sidebars_widgets();
		$num_widgets = 0;
		foreach ( (array) $sidebars_widgets as $k => $v ) {
			if ( 'wp_inactive_widgets' == $k )
				continue;
			if ( is_array($v) )
				$num_widgets = $num_widgets + count($v);
		}
		$num = number_format_i18n( $num_widgets );

		$switch_themes = $ct->title;
		if ( current_user_can( 'switch_themes') ) {
			echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
			$switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
		}
		if ( current_user_can( 'edit_theme_options' ) ) {
			printf(_n('Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $switch_themes, $num);
		} else {
			printf(_n('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $switch_themes, $num);
		}
	} else {
		if ( current_user_can( 'switch_themes' ) ) {
			echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
			printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
		} else {
			printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
		}
	}
	echo '</p>';

	update_right_now_message();

	echo "\n\t".'<br class="clear" /></div>';
	do_action( 'rightnow_end' );
	do_action( 'activity_box_end' );
}
function wpmods_add_dashboard_widget() {
	wp_add_dashboard_widget( 'dashboard_right_now', 'About Library', 'wpmods_dashboard_widget' );
}
add_action( 'wp_dashboard_setup', 'wpmods_add_dashboard_widget' );
?>